package tw.miku.protocol.codec.room;

import java.nio.charset.CharacterCodingException;

import org.apache.mina.core.buffer.IoBuffer;

import tw.miku.constants.ProtocalConstants;
import tw.miku.model.User;
import tw.miku.protocol.codec.AbstractResponseMessagePack;

public class UserEnterRoomResponsePack extends AbstractResponseMessagePack
{

	public int roomId;
	public User user;

	public UserEnterRoomResponsePack()
	{

	}

	@Override
	public IoBuffer encode() throws CharacterCodingException
	{
		IoBuffer buf = IoBuffer.allocate(100).setAutoExpand(true);
		buf.position(4);
		buf.putShort(getTag());
		buf.putShort((short) 0);
		buf.putUnsignedInt(roomId);
		buf.put(user.getInfo());

		buf.flip();
		buf.putUnsignedInt(buf.limit() - 4);
		buf.position(0);
		return buf;
	}

	@Override
	public short getTag()
	{
		return ProtocalConstants.USER_ENTER_ROOM;
	}

}
